<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<jsp:include page="../common/menu.jsp" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>添加派车单</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
	<script src="<%=basePath%>js/tools.js"></script>
</head>
<body class="form-wrap">

	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-card-header">修改派车单</div>
			<div class="layui-card-body" style="padding: 15px;">
				<form class="layui-form" action="#"
					name="dispatchInfo" id="dispatchInfo" method="post" lay-filter="component-form-group">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">派车单号</label>
							<div class="layui-input-inline">
								<input type="hidden" value="${dispatch.id}" name="id">
								<input type="text" name="dispatchNum" id="dispatchNum" value="${dispatch.dispatchNum}"
									lay-verify="title" readonly="readonly" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">登记日期</label>
							<div class="layui-input-inline">
								<input type="text" name="createTime" value="<fmt:formatDate value='${dispatch.createTime}' type='time' pattern="yyyy-MM-dd HH:mm:ss"/>" readonly="readonly" lay-verify="required"
									autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">业务员</label>
							<div class="layui-input-inline">
								<select name="salesmanId" id="salesmanId" lay-filter="salesman" lay-search>
									<option value="">请选择货业务员</option>
									<c:forEach var="sale" items="${saleList}">
										<option value="${sale.id }"
												data-salesmanName="${sale.salesmanName }"
												<c:if test="${dispatch.salesmanId eq sale.id}"> selected </c:if>
										>${sale.salesmanName }</option>
									</c:forEach>
								</select>
								<input type="hidden" name="salesmanName" id="salesmanName" value="${dispatch.salesmanName}">
							</div>
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">用车单位</label>
							<div class="layui-input-inline">
								<select name="companyId" id="companyId" lay-verify="" autocomplete="off" lay-filter="company" lay-search>
            						<option value="">请选用车单位</option>
            						<c:forEach var="company" items="${companyList}">
            							<option value="${company.id }"
												data-companyName="${company.companyName }"
												data-companyContactName="${company.contactName }"
												data-companyContactTel="${company.contactTel }"
												<c:if test="${dispatch.companyId eq company.id}"> selected </c:if>
										>${company.companyName }(${company.contactName })</option>
            						</c:forEach>
        						</select>
								<input type="hidden" name="companyName" id="companyName" value="${dispatch.companyName}" value="">
							<!-- 	<input type="text" name="bdRelatedPartyNo" autocomplete="off"
									class="layui-input"> -->
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">联系人</label>
							<div class="layui-input-inline">
								<input type="text" name="companyContactName" readonly="readonly" id="companyContactName" value="${dispatch.companyContactName}" autocomplete="off"
									   class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">联系电话</label>
							<div class="layui-input-inline">
								<input type="text" name="companyContactTel" readonly="readonly" id="companyContactTel" value="${dispatch.companyContactTel}" autocomplete="off"
									class="layui-input">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">出车时间</label>
							<div class="layui-input-inline">
								<input type="text" name="startTime" id="startTime" value="<fmt:formatDate value='${dispatch.startTime}' type='time' pattern="yyyy-MM-dd HH:mm:ss"/>" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">支付方式</label>
							<div class="layui-input-inline">
								<select name="payType" id="payType" lay-verify="" autocomplete="off" >
									<option value="现金" <c:if test="${dispatch.payType eq '现金'}"> selected </c:if> >现金</option>
									<option value="支付宝" <c:if test="${dispatch.payType eq '支付宝'}"> selected </c:if> >支付宝</option>
									<option value="微信" <c:if test="${dispatch.payType eq '微信'}"> selected </c:if> >微信</option>
									<option value="刷卡" <c:if test="${dispatch.payType eq '刷卡'}"> selected </c:if> >刷卡</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">所属类别</label>
							<div class="layui-input-inline">
								<select name="carType" id="carType" lay-verify="">
									<option value="包车" <c:if test="${dispatch.carType eq '包车'}"> selected </c:if> >包车</option>
									<option value="拼车" <c:if test="${dispatch.carType eq '拼车'}"> selected </c:if> >拼车</option>
									<option value="租车" <c:if test="${dispatch.carType eq '租车'}"> selected </c:if> >租车</option>
								</select>
							</div>
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">起始地点</label>
						<div class="layui-input-block">
							<input type="text" name="startAddress" value="${dispatch.startAddress}" style="width: 88%" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">车牌号码</label>
							<div class="layui-input-inline">
								<select name="vehicleId" id="vehicleId" lay-verify="" autocomplete="off" lay-filter="vehicle" lay-search>
									<option value="">请选用车辆</option>
									<c:forEach var="vehicle" items="${vehicleList}">
										<option value="${vehicle.id }"
												data-vehicleNum="${vehicle.vehicleNum }"
												<c:if test="${dispatch.vehicleId eq vehicle.id}"> selected </c:if>
										>${vehicle.vehicleNum }</option>
									</c:forEach>
								</select>
								<input type="hidden" name="vehicleNum" id="vehicleNum" value="${dispatch.vehicleNum}" value="">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">驾驶员</label>
							<div class="layui-input-inline">
								<select name="pilotId" id="pilotId" lay-verify="" autocomplete="off" lay-filter="pilot" lay-search>
									<option value="">请选用驾驶员</option>
									<c:forEach var="pilot" items="${pilotList}">
										<option value="${pilot.id }"
												data-pilotName="${pilot.pilotName }"
												<c:if test="${dispatch.pilotId eq pilot.id}"> selected </c:if>
										>${pilot.pilotName }</option>
									</c:forEach>
								</select>
								<input type="hidden" name="pilotName" id="pilotName" value="${dispatch.pilotName}">
							</div>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">状态</label>
							<div class="layui-input-inline">
								<select name="status" id="status" lay-verify="" autocomplete="off" lay-filter="pilot" lay-search>
									<option value="1">未审核-未收款</option>
								</select>
							</div>
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">租车费</label>
							<div class="layui-input-inline">
								<input type="float" name="totalMoney" id="totalMoney" value="${dispatch.totalMoney}" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">折让金额</label>
							<div class="layui-input-inline">
								<input type="float" name="saleMoney" id="saleMoney" value="${dispatch.saleMoney}" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">实际金额</label>
							<div class="layui-input-inline">
								<input type="float" name="realMoney" id="realMoney" value="${dispatch.realMoney}" readonly="readonly" class="layui-input">
							</div>
						</div>
					</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<textarea name='remark' placeholder="请输入内容" class="layui-textarea">${dispatch.remark}</textarea>
				</div>
			</div>
			<div class="layui-form-item layui-layout-admin">
				<div class="layui-input-block">
					<div class="layui-footer" style="text-align: center;">
						<button class="layui-btn" id="tj" type="button">立即提交</button>
						<a href="<%=basePath%>dispatch/toDispatchList" class="layui-btn layui-btn-primary">返回列表</a>
					</div>
				</div>
			</div>
			</form>
		</div>
	</div>
	</div>

</body>

</html>

<script>

	$('document').ready(function() {

		$("#totalMoney").change(function () {
			var totalMoney = $("#totalMoney").val();
			var saleMoney = $("#saleMoney").val();
			if(totalMoney!=0 && saleMoney!=0){
				$("#realMoney").val((totalMoney-saleMoney).toFixed(2));
			}
		});

		$("#saleMoney").change(function () {
			var totalMoney = $("#totalMoney").val();
			var saleMoney = $("#saleMoney").val();
			if(totalMoney!=0 && saleMoney!=0){
				$("#realMoney").val((totalMoney-saleMoney).toFixed(2));
			}
		});

		$("#tj").click(function () {
			//var jsonObj = $('#dispatchInfo').serializeJSON();
			var data = JSON.stringify($('#dispatchInfo').serializeJSON());
			// var data ={
			// 	"realMoney":"3.5"
			// };
			//var data2 = JSON.stringify(data);
			console.log(data);
			$.ajax({
				type:'post'
				,url:'<%=basePath%>dispatch/editDispatch'
				,data:data
				,dataType:'json'
				,contentType:'application/json;charset=utf-8'
				,success:function(data) {
					console.log(data)
					if(data.responseHead.code=200){
						window.location.href="<%=basePath%>dispatch/toDispatchList";
					}
				}
			})
		});

		layui.use(['form','laydate'], function() {
			var $ = layui.$,
				laydate = layui.laydate,
				form = layui.form;

			 form.on('select(salesman)',function (data) {
				var name = $(data.elem).find("option:selected").attr("data-salesmanName");
				console.log(name);
				$("#salesmanName").val(name);
			 });
			form.on('select(pilot)',function (data) {
				var name = $(data.elem).find("option:selected").attr("data-pilotName");
				console.log(name);
				$("#pilotName").val(name);
			});
			form.on('select(vehicle)',function (data) {
				var name = $(data.elem).find("option:selected").attr("data-vehicleNum");
				console.log(name);
				$("#vehicleNum").val(name);
			});
			form.on('select(company)',function (data) {
				var companyName = $(data.elem).find("option:selected").attr("data-companyName");
				var companyContactName = $(data.elem).find("option:selected").attr("data-companyContactName");
				var companyContactTel = $(data.elem).find("option:selected").attr("data-companyContactTel");

				$("#companyName").val(companyName);
				$("#companyContactName").val(companyContactName);
				$("#companyContactTel").val(companyContactTel);
			});


			laydate.render({
				elem : '#startTime',
				type : 'datetime',
				trigger : 'click'
			});

			/* 监听提交 */
			// form.on('submit(component-form-demo1)', function(data) {
			// 	var form = document.forms[0];
			// 		form.submit();
			// 	return false;
			// });



		});
	});
</script>

<jsp:include page="../common/js.jsp" />